<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>垂直居中</title>
    <link rel="stylesheet" href="../public.css">
    <style>
        .box {
            position: relative;
            height: 200px;
            margin: 20px auto;
            background: yellowgreen;
        }

        .con {
            position: absolute;
            top: 50%;
            left: 50%;
            /* margin-top: -10px;
            margin-left: -10px; */
            transform: translate(-50%, -50%);
            width: 20px;
            height: 20px;
            background: red;
        }

        .con1 {
            background: red;
            width: .1em;
            padding: 1em 1.5em;
            margin: 1vh auto 0;
            transform: translateY(-50%);
        }

        .con2 {
            width: 20px;
            height: 20px;
            background: red;
        }

        .back1 {
            display: flex;
            justify-content: center;
            align-items: center;
        }
    
    </style>
</head>

<body>
    <div class="content">
        <h1>基于绝对定位的解决方案</h1>
        <ul>
            <li>如果一个行内元素水平居中，对他的父元素设置text-align:center;</li>
            <li>如果一个块元素水平居中，对他的自身设置margin:auto;</li>

        </ul>
        <div class="box">
            <div class="con">

            </div>
        </div>
        <div class="box">
            <div class="con1">

            </div>
        </div>
        <div class="box back1">
            <div class="con2">

            </div>
        </div>
    </div>
</body>

</html>